<?php
namespace lib\http;
class TCurl
{
    public static function DoGet($url,$timeout = 5)
    {
        if(!$url || $timeout <= 0) return false;

        $con = curl_init((string)$url);
        curl_setopt($con, CURLOPT_HEADER, false);
        curl_setopt($con, CURLOPT_RETURNTRANSFER,true);
        curl_setopt($con, CURLOPT_TIMEOUT, (int)$timeout);
        curl_setopt($con, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($con, CURLOPT_SSL_VERIFYHOST,false);

        $rtl=curl_exec($con);
        curl_close($con);

        return $rtl;
    }

    public static function DoPost($url,$arr_post,$is_json=false,$timeout=5)
    {
        if(!$url || !$arr_post || $timeout <=0) return false;
        if($is_json) $arr_post=json_encode($arr_post);

        $con = curl_init((string)$url);
        curl_setopt($con, CURLOPT_HEADER, false);
        curl_setopt($con, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($con, CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($con, CURLOPT_POST,true);
        curl_setopt($con, CURLOPT_POSTFIELDS, $arr_post);
        curl_setopt($con, CURLOPT_RETURNTRANSFER,true);
        curl_setopt($con, CURLOPT_TIMEOUT,(int)$timeout);

        $rtl=curl_exec($con);
        curl_close($con);

        return $rtl;
    }

}